import 'package:enterprise_v6_app/app/components/custom_refresh.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/http/http.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/data/entities/application/major_hazard/hazard_assessment_entity.dart';
import 'package:enterprise_v6_app/app/modules/application/major_hazard/assessment/assess_type.dart';
import 'package:enterprise_v6_app/app/modules/application/major_hazard/major_hazard_controller.dart';

class HazardAssessmentController extends GetxController {
  final keyEvaluation = GlobalKey<CustomEasyRefreshListState>();
  final keyAssessment = GlobalKey<CustomEasyRefreshListState>();

  Future<List<HazardAssessmentEntity>> dataLoad(int idx, int size, HazardAssessmentType type) async {
    final queryParameters = <String, dynamic>{};
    queryParameters['pageNum'] = idx;
    queryParameters['pageSize'] = size;
    queryParameters['fileType'] = type.toInt;
    queryParameters['riskObjectId'] = Get.find<MajorHazardController>().selectedHazard?.id;

    final res = await HttpUtil()
        .generateGetRequest<List<HazardAssessmentEntity>>(
          Interface.getHazardAssessmentPage,
          queryParameters: queryParameters,
        )
        .execute();
    final data = res.data ?? [];
    data.sort((a, b) => b.updateDate?.compareTo(a.updateDate ?? '') ?? 0);
    return data;
  }
}
